/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uk.ac.bath.domains.mover;

import java.util.Collection;
import java.util.Vector;
import uk.ac.bath.legacy.Cell;
import uk.ac.bath.legacy.CellFactoryIF;
//import uk.ac.bath.base.EnvironmentIF;
import uk.ac.bath.legacy.Point;
import uk.ac.bath.machines.bool.LogicalMachine;

import uk.ac.bath.machines.bool.Palettes;
import uk.ac.bath.util.MyRandom;
import uk.ac.bath.util.Tweakable;
import uk.ac.bath.util.TweakableInt;

/**
 *
 * @author pjl
 */
public class MoverCellFactory implements CellFactoryIF,MoverCellFactoryIF {

    public Vector<Tweakable> tweaks = new Vector<Tweakable>();
    public TweakableInt maxOperatorsPerCell =
            new TweakableInt(tweaks, 10, 1000, 50, "MaxMachineSize");
    public TweakableInt initFit =
            new TweakableInt(tweaks, 0, 200, 5, "InitialFitness");
    final public static int minOperatorsPerCell = 10;
    private MoverEnvironment env;

    
//    static  PalleteIF pallete;
//
//    static {
//        Vector<Operator> pal = new Vector<Operator>();
//        pal.add(new And());
//        pal.add(new Or());
//        pal.add(new Not());
//        pal.add(new Link());
//// 	pallete.add(new X());
//// 	pallete.add(new Mult());
//        pal.add(new Cmp());
//        pal.add(new Diff());
//        pal.add(new On());
//        pal.add(new Off());
//        pal.add(new Int());
//        pallete=new PalleteIF( pal);
//    }

    public MoverCellFactory() {
        tweaks.addAll(MoverCellMrkI.tweaks);
        tweaks.addAll(LogicalMachine.tweaks);
    }

   

    public Cell createRandomCell(Point p) {

        int nOps = MoverCellMrkI.minOperatorsPerCell +
                MyRandom.nextInt(maxOperatorsPerCell.intValue() - minOperatorsPerCell);
        LogicalMachine m = new LogicalMachine(nOps, Palettes.full);

        int cid = Cell.nextId();
        String tag = "MrkI:" + cid;

        return new MoverCellMrkI(env,m, p,
                initFit.doubleValue(),
                cid, 0, 0, tag);
    }


    public void mutate(Cell cell) {
        MoverCell mv = (MoverCell) cell;
        ((LogicalMachine) mv.getMachine()).mutate();
    }

    public Collection<Tweakable> getTweaks() {
        return tweaks;
    }

    public void setEnvironment(MoverEnvironment env) {
        this.env=(MoverEnvironment) env;
    }

    public double getInitFitness() {
        return initFit.doubleValue();
    }
}
